package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entity.Payment;
import com.atguigu.commonutils.R;
import com.atguigu.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cdd
 * @since 2021-03-08
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("create")
    public R create(@RequestBody Payment payment) {
        // 返回添加支付的ID
        Long paymentId = paymentService.create(payment);
        return R.ok().data("paymentId",paymentId).message("server port:" + serverPort);
    }

    @GetMapping("getPaymentById/{id}")
    public R getPaymentById(@PathVariable Long id) {
        Payment payment = paymentService.getById(id);
        return R.ok().data("payment",payment).message("server port:" + serverPort);
    }
}

